<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>股票回测系统</title>
    <style>
        body {
            font-family: sans-serif;
            margin: 0;
            padding: 2em;
            background: #f8f8f8;
            text-align: center;
        }
        .form-container {
            max-width: 600px;
            background: #fff;
            padding: 2em;
            border: 1px solid #ddd;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            margin: 2em auto;
        }
        .form-group {
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 1.5em;
        }
        .form-group label {
            width: 120px;
            font-weight: bold;
            text-align: right;
            margin-right: 1em;
        }
        .form-group input,
        .form-group select {
            width: 200px;
            height: 34px; /* 统一高度 */
            padding: 8px;
            font-size: 14px; /* 统一字体大小 */
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box; /* 确保 padding 不影响宽度 */
        }
        .form-group button {
            padding: 10px 20px;
            background: #007bff;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background 0.3s;
        }
        .form-group button:hover {
            background: #0056b3;
        }
        #strategy-description {
            max-width: 600px;
            background: #fff;
            padding: 1.5em;
            border: 1px solid #ddd;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            margin: 2em auto;
            text-align: left;
        }
        h1 {
            color: #333;
            margin-bottom: 1.5em;
        }
        h3 {
            margin-top: 0;
            color: #333;
        }
        @media (max-width: 600px) {
            .form-group {
                flex-direction: column;
                align-items: flex-start;
            }
            .form-group label {
                text-align: left;
                margin-bottom: 0.5em;
            }
            .form-group input,
            .form-group select,
            .form-group button {
                width: 100%;
                height: 34px; /* 移动端保持高度一致 */
            }
        }
    </style>
    <script>
        // 策略描述（从后端传入）
        const strategyDescriptions = {{ strategy_descriptions | tojson }};

        // 页面加载时显示默认策略描述
        window.onload = function() {
            const strategySelect = document.getElementById("strategy");
            const descriptionDiv = document.getElementById("strategy-description");
            descriptionDiv.innerHTML = strategyDescriptions[strategySelect.value] || "";
        };

        // 策略选择变化时更新描述
        function updateStrategyDescription() {
            const strategySelect = document.getElementById("strategy");
            const descriptionDiv = document.getElementById("strategy-description");
            descriptionDiv.innerHTML = strategyDescriptions[strategySelect.value] || "";
        }
    </script>
</head>
<body>
    <h1>股票回测系统</h1>
    <div class="form-container">
        <form method="POST" action="/">
            <div class="form-group">
                <label for="ticker">股票代码:</label>
                <input type="text" id="ticker" name="ticker" required>
            </div>
            <div class="form-group">
                <label for="start">开始日期:</label>
                <input type="date" id="start" name="start" value="2025-01-01" required>
            </div>
            <div class="form-group">
                <label for="end">结束日期:</label>
                <input type="date" id="end" name="end" value="2025-06-09" required>
            </div>
            <div class="form-group">
                <label for="cash">初始资金:</label>
                <input type="number" id="cash" name="cash" step="1" value="10000" required>
            </div>
            <div class="form-group">
                <label for="strategy">交易策略:</label>
                <select id="strategy" name="strategy" onchange="updateStrategyDescription()">
                    {% for strategy in strategies %}
                        <option value="{{ strategy }}">{{ strategy | capitalize }}</option>
                    {% endfor %}
                </select>
            </div>
            <div class="form-group">
                <button type="submit">运行回测</button>
            </div>
        </form>
    </div>
    <div id="strategy-description"></div>
</body>
</html>
